Path: blob/master/src/packages/next/pages/sso/[id].tsx
1543 views
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { r_human_list } from "@cocalc/frontend/components/r_human_list";6import { Button, Layout, Typography } from "antd";7import Footer from "components/landing/footer";8import Head from "components/landing/head";9import Header from "components/landing/header";10import Main from "components/landing/main";11import SanitizedMarkdown from "components/misc/sanitized-markdown";12import { ssoNav } from "components/sso";13import basePath from "lib/base-path";14import { Customize, CustomizeType } from "lib/customize";15import { getOneSSO } from "lib/sso/sso";16import withCustomize from "lib/with-customize";17import Link from "next/link";18import { join } from "path";19import { SSO_SUBTITLE } from ".";2021import type { JSX } from "react";2223const { Paragraph, Text } = Typography;2425interface Props {26customize: CustomizeType;27id: string;28descr?: string;29display: string;30icon?: string;31domains: string[];32}3334export default function Signup(props: Props) {35const { id, descr, display, icon, domains, customize } = props;3637function renderDescr() {38const fallback = `If you have an account at this provider,39you can signup here to get access to ${customize.siteName}.`;40const md = `## ${display}\n\n${descr ?? fallback}`;41return <SanitizedMarkdown value={md} />;42}4344function renderIcon() {45if (icon == null) return null;46return (47<div style={{ float: "right" }}>48<img src={icon} width={100} height={100} />49</div>50);51}5253function renderExclusiveDomains() {54if (domains.length === 0) return null;55return (56<Paragraph>57This is required for email addresses at{" "}58{r_human_list(59(domains ?? []).map((d) => (60<Text code key={d}>61{d}62</Text>63))64)}65</Paragraph>66);67}6869function renderButton() {70const href = join(basePath, "auth", id);71return (72<Button73href={href}74type="primary"75size="large"76style={{ marginTop: "50px" }}77>78Sign up using {display}79</Button>80);81}8283function main() {84return (85<>86{renderIcon()}87{renderDescr()}88{renderExclusiveDomains()}89{renderButton()}90</>91);92}9394function nav(): JSX.Element[] {95return [...ssoNav(), <Link href={`/sso/{id}`}>{display}</Link>];96}9798return (99<Customize value={customize}>100<Head title={`${SSO_SUBTITLE} – ${display}`} />101<Layout style={{ background: "white" }}>102<Header />103<Main nav={nav()}>{main()}</Main>104<Footer />105</Layout>106</Customize>107);108}109110export async function getServerSideProps(context) {111const { id } = context.params;112const info = await getOneSSO(id);113return await withCustomize({ context, props: { ...info } });114}115116117